﻿using Mapster;
using BJ.AuthEntity.Models;

namespace BJ.AuthEntity.DtoModels
{
    /// <summary>
    /// 类型映射
    /// </summary>
    public class Mapper : IRegister
    {
        /// <summary>
        /// 类型映射
        /// </summary>
        /// <param name="config"></param>
        public void Register(TypeAdapterConfig config)
        {
            config.ForType<AdminUserAuth, UserAuthDto>()
                .Map(src => src.UserName, dto => dto.User.Name)
                .Map(src => src.UserId, dto => dto.User.Id)
                .Map(src => src.RoleName, dto => dto.User.Role.Name)
                .Map(src => src.Level, dto => dto.User.Role.Level)
                .Map(src => src.Emil, dto => dto.User.Emil)
                .Map(src => src.Phone, dto => dto.User.Phone)
                .Map(src => src.IsAdmin, dto => dto.User.Role.IsAdmin);

            config.ForType<UserAuth, UserAuthDto>()
                .Map(src => src.UserName, dto => dto.User.Name)
                .Map(src => src.UserId, dto => dto.User.Id)
                .Map(src => src.Emil, dto => dto.User.Emil)
                .Map(src => src.Phone, dto => dto.User.Phone);
        }
    }
}
